package mmoon.mmoonstory;

import mmoon.mmoonstory.interfaces.InitWorldGenerator;
import mmoon.mmoonstory.proxy.CommonProxy;
import net.minecraft.command.CommandBase;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.common.IWorldGenerator;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.SidedProxy;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.event.FMLServerStartingEvent;
import net.minecraftforge.fml.common.registry.GameRegistry;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

@Mod(modid = MMoonStory.MOD_ID, name = MMoonStory.MOD_NAME, version = MMoonStory.VERSION, acceptedMinecraftVersions = MMoonStory.ACCEPT_MC_VER, acceptableRemoteVersions = MMoonStory.ACCEPT_MC_VER, useMetadata = true)
public final class MMoonStory {
    public static final String MOD_ID = "mmoonstory";
    public static final String MOD_NAME = "MMoon's Story";
    public static final String VERSION = "1.0";
    public static final String ACCEPT_MC_VER = "1.12.2";
    public static final Logger logger = LogManager.getLogger(MOD_ID);

    @SidedProxy(serverSide = "mmoon.mmoonstory.proxy.CommonProxy", clientSide = "mmoon.mmoonstory.proxy.ClientProxy")
    public static CommonProxy MMoonProxy;
    @Mod.Instance(MOD_ID)
    public static MMoonStory INSTANCE;

    @Mod.EventHandler
    public void preinit(FMLPreInitializationEvent event) {
        logger.info(">> to be initialized...");
        GameRegistry.registerWorldGenerator(MMoonUtils.GEN_EMERALD, 3);
        for (IWorldGenerator i : MMoonUtils.MMOON_WORLD_GENERATORS) {
            if(i instanceof InitWorldGenerator){
                ((InitWorldGenerator) i).reg();
            }
        }
    }

    @Mod.EventHandler
    public void init(FMLInitializationEvent event) {
        logger.info(">> initializing...");
        GameRegistry.addSmelting(Items.REDSTONE, new ItemStack(Items.DYE, 8, 1), 1);
    }

    @Mod.EventHandler
    public void postinit(FMLPostInitializationEvent event) {
        logger.info(">> initialized.");
    }

    @Mod.EventHandler
    public void onServerStarting(FMLServerStartingEvent event) {
        for (CommandBase i : MMoonUtils.MMOON_COMMANDS) {
            event.registerServerCommand(i);
        }
    }
}
